package com.cloud.tsp.controller;

import com.cloud.api.domain.alarm.AlarmDetail;
import com.cloud.core.util.R;
import com.cloud.api.domain.alarm.QueryAlarm;
import com.cloud.api.domain.alarm.VehicleAlarm;
import com.cloud.api.constants.StrVo;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.service.IVehicleAlarmService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * OLAP 前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2024-01-23
 */
@RestController
@RequestMapping("/vehicle-alarm")
@Validated
public class VehicleAlarmController {

    @Resource
    private IVehicleAlarmService vehicleAlarmService;


    @Tag(name = "v1.0")
    @Operation(summary = "查询报警明细列表（管理）")
    @PostMapping("/getVehicleAlarmList")
    @Log(title = "报警管理-查询报警明细列表", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<VehicleAlarm> selectVehicleAlarmList(@RequestBody @Validated QueryAlarm para){
        return vehicleAlarmService.selectVehicleAlarmList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "查询报警详情（管理）")
    @PostMapping("/getVehicleDetail")
    @Log(title = "报警管理-查询报警明细列表", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<AlarmDetail> selectVehicleDetail(@RequestBody @Validated StrVo para){
        AlarmDetail alarmDetail = vehicleAlarmService.selectVehicleDetail(para.getId());
        return R.ok(alarmDetail);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "处理详情（管理）")
    @PostMapping("/getVehicleAlarmDetail")
    @Log(title = "报警管理-处理详情", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<VehicleAlarm> selectVehicleAlarmDetail(@RequestBody @Validated StrVo para){
        return R.ok(vehicleAlarmService.selectVehicleAlarmDetail(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "vin id查询报警信息（实时监控）")
    @PostMapping("/getAlarmListByVin")
    @Log(title = "报警管理-vin查询报警信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<VehicleAlarm> selectAlarmListByVin(@RequestBody StrVo para){
        return R.ok(vehicleAlarmService.selectAlarmListByVin(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "vin报警信息导出（实时监控）")
    @PostMapping("/exportAlarmByVin")
    @Log(title = "报警管理-vin报警信息导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportAlarmByVin(@RequestParam String id, HttpServletResponse response) throws IOException {
        vehicleAlarmService.exportAlarmByVin(id,response);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "处理报警（管理）")
    @PostMapping("/handleAlarm")
    @Log(title = "报警管理-处理报警", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R handleAlarm(@RequestBody @Validated VehicleAlarm para){
        vehicleAlarmService.handleAlarm(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "批量处理报警（管理）")
    @PostMapping("/handleAlarmList")
    @Log(title = "报警管理-批量处理报警", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R handleAlarmList(@RequestBody @Validated @Size(min = 1) List<@Valid VehicleAlarm> para){

        vehicleAlarmService.handleAlarmList(para);
        return R.ok();
    }

    /*@Tag(name = "v1.0")
    @Operation(summary = "报警明细导出")
    @PostMapping("/exportVehicleAlarm")
    @Log(title = "报警管理-报警明细导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportVehicleAlarm(QueryAlarm para, HttpServletResponse response) throws IOException {
        vehicleAlarmService.exportVehicleAlarm1(para,response);
    }*/

}